<template>
  <div>
    <div class="title">查询移位</div>
    <base-list ref="shiftSearch"
               :condition="condition"
               :datas.sync="shiftSearchData"
               :pageSearch="pageSearch">
      <el-form :inline="true"
               :model="condition"
               class="search-form"
               slot="search"
               ref="aList"
               label-width="100px">
        <el-row>
          <el-col :span="6"
                  class="search-width6">
            <el-form-item label="移位单状态">
              <el-select v-model="condition['search_EQ_status']"
                         placeholder="请选择"
                         clearable
                         filterable>
                <el-option v-for="[key, val] in _dictShiftStatus"
                           :key="key"
                           :label="val"
                           :value="key"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6"
                  class="search-width6">
            <el-form-item label="移位类型">
              <el-select v-model="condition['search_EQ_relocationType']"
                         placeholder="请选择"
                         clearable
                         filterable>
                <el-option v-for="[key, val] in _dictRelocationType"
                           :key="key"
                           :label="val"
                           :value="key"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6"
                  class="search-width6">
            <el-form-item label="移位单据号">
              <el-input type="text"
                        v-model="condition['search_EQ_planNo']"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6"
                  class="search-width6">
            <el-form-item label="是否计件">
              <el-select v-model="condition['search_EQ_ifPieceWork']"
                         placeholder="请选择"
                         clearable
                         filterable>
                <el-option v-for="[key, val] in _dictTrueOrFalse"
                           :key="key"
                           :label="val"
                           :value="key"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="9"
                  class="search-width8">
            <el-form-item label="创建时间"
                          class="label-width">
              <el-date-picker style="width:150px;"
                              v-model="condition['search_GTE_createDateTime']"
                              type="date"
                              placeholder="选择日期"
                              value-format="yyyy-MM-dd 00:00:00"> </el-date-picker> 至
              <el-date-picker style="width:150px;"
                              v-model="condition['search_LTE_createDateTime']"
                              type="date"
                              placeholder="选择日期"
                              value-format="yyyy-MM-dd 23:59:59"> </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="9"
                  class="search-width8">
            <el-form-item label="开始作业时间"
                          class="label-width">
              <el-date-picker style="width:150px;"
                              v-model="condition['search_GTE_startTime']"
                              type="date"
                              placeholder="选择日期"
                              value-format="yyyy-MM-dd 00:00:00"> </el-date-picker> 至
              <el-date-picker style="width:150px;"
                              v-model="condition['search_LTE_startTime']"
                              type="date"
                              placeholder="选择日期"
                              value-format="yyyy-MM-dd 23:59:59"> </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="9"
                  class="search-width8">
            <el-form-item label="完成作业时间"
                          class="label-width">
              <el-date-picker style="width:150px;"
                              v-model="condition['search_GTE_endTime']"
                              type="date"
                              placeholder="选择日期"
                              value-format="yyyy-MM-dd 00:00:00"> </el-date-picker> 至
              <el-date-picker style="width:150px;"
                              v-model="condition['search_LTE_endTime']"
                              type="date"
                              placeholder="选择日期"
                              value-format="yyyy-MM-dd 23:59:59"> </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-button type="primary"
                       icon="el-icon-search"
                       class="ml-80"
                       @click="loadData">查 询</el-button>
            <el-button formVisible="true"
                       icon="el-icon-refresh"
                       @click="resuleBtn('aList')">
              重置
            </el-button>
          </el-col>
        </el-row>
      </el-form>
      <el-table slot="list"
                :data="shiftSearchData"
                border
                stripe
                highlight-current-row
                @current-change="handleCurrentChange"
                max-height="550">
        <el-table-column label="序号"
                         type="index"
                         width="50"></el-table-column>
        <el-table-column prop="planNo"
                         label="移位单据号"
                         min-width="100"></el-table-column>
        <el-table-column prop="status"
                         label="状态"
                         min-width="80">
          <template slot-scope="scope">
            {{ scope.row.status | _filterJobStatus }}
          </template>
        </el-table-column>
        <el-table-column prop="relocationType"
                         label="移位类型"
                         min-width="80">
          <template slot-scope="scope">
            {{ scope.row.relocationType | _filterRelocationType }}
          </template>
        </el-table-column>
        <el-table-column prop="ifSpecifyCar"
                         label="是否指定内转车"
                         min-width="150">
          <template slot-scope="scope">
            {{ scope.row.ifSpecifyCar | _filterTrueOrFalse }}
          </template>
        </el-table-column>
        <el-table-column prop="carNo"
                         label="内转车号"
                         min-width="120"></el-table-column>
        <el-table-column prop="ifPieceWork"
                         label="是否计件"
                         min-width="80">
          <template slot-scope="scope">
            {{ scope.row.ifPieceWork | _filterTrueOrFalse }}
          </template>
        </el-table-column>
        <el-table-column prop="createBy"
                         label="创建人"
                         min-width="120"></el-table-column>
        <el-table-column prop="createDateTime"
                         label="创建时间"
                         min-width="150"></el-table-column>
        <el-table-column prop="startTime"
                         label="开始作业时间"
                         min-width="150"></el-table-column>
        <el-table-column prop="endTime"
                         label="完成作业时间"
                         min-width="150"></el-table-column>
        <el-table-column fixed="right"
                         align="center"
                         label="操作"
                         width="240">
          <template slot-scope="scope">
            <el-button size="small"
                       type="text"
                       @click.stop="handleDialogFormOpen(true,scope.row)">
              编辑
            </el-button>
            <el-button type="text"
                       class="danger"
                       size="small"
                       @click.stop="handleRemove(scope.row)">删除
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </base-list>
    <div v-show="show">
      <el-row>
        <el-col :span="14">
          <div class="control-line">
            移位单明细
          </div>
        </el-col>
      </el-row>
      <el-table :data="shiftDetailData"
                border
                stripe
                max-height="550">
        <el-table-column type="expand"
                         width="60">
          <template slot-scope="props">
            <el-form label-position="left"
                     inline
                     class="demo-table-expand">
              <el-col :span="6"
                      class="table-expand-style">
                <el-form-item label="移出作业点">
                  <span>{{ props.row.startJobPointName}}</span>
                </el-form-item>
              </el-col>
              <el-col :span="6"
                      class="table-expand-style">
                <el-form-item label="移出操作人">
                  <span>{{ props.row.startBy }}</span>
                </el-form-item>
              </el-col>
              <el-col :span="6"
                      class="table-expand-style">
                <el-form-item label="移出时间">
                  <span>{{ props.row.measureWay }}</span>
                </el-form-item>
              </el-col>
              <el-col :span="6"
                      class="table-expand-style">
                <el-form-item label="移入作业点">
                  <span>{{ props.row.startTime}}</span>
                </el-form-item>
              </el-col>
              <el-col :span="6"
                      class="table-expand-style">
                <el-form-item label="移入操作人">
                  <span>{{ props.row.endBy}}</span>
                </el-form-item>
              </el-col>
              <el-col :span="6"
                      class="table-expand-style">
                <el-form-item label="移入时间">
                  <span>{{ props.row.endTime}}</span>
                </el-form-item>
              </el-col>
              <el-col :span="6"
                      class="table-expand-style">
                <el-form-item label="物资ID">
                  <span>{{ props.row.inventoryId}}</span>
                </el-form-item>
              </el-col>
            </el-form>
          </template>
        </el-table-column>
        <el-table-column label="序号"
                         type="index"
                         width="50"></el-table-column>
        <el-table-column prop="trackingNo"
                         label="跟踪号"
                         min-width="100"></el-table-column>
        <el-table-column prop="status"
                         label="作业状态"
                         min-width="100">
          <template slot-scope="scope">
            {{ scope.row.status | _filterCheckStatus }}
          </template>
        </el-table-column>
        <el-table-column prop="warehouseName"
                         label="原仓库"
                         min-width="100">
        </el-table-column>
        <el-table-column prop="targetWarehouseName"
                         label="新仓库"
                         min-width="100">
        </el-table-column>
        <el-table-column prop="roomName"
                         label="原库房"
                         min-width="100"></el-table-column>
        <el-table-column prop="targetRoomName"
                         label="新库房"
                         min-width="100"></el-table-column>
        <el-table-column prop="roomLocation"
                         label="原库位"
                         min-width="100"></el-table-column>
        <el-table-column prop="targetRoomLocation"
                         label="新库位"
                         min-width="100"></el-table-column>
        <el-table-column prop="cargoName"
                         label="品名"
                         min-width="100"></el-table-column>
        <el-table-column prop="normStr"
                         label="规格"
                         min-width="120"></el-table-column>
        <el-table-column prop="material"
                         label="材质"
                         min-width="100"></el-table-column>
        <el-table-column prop="madeBy"
                         label="生产厂家"
                         min-width="100"></el-table-column>
        <el-table-column prop="carNo"
                         label="内转车号"
                         min-width="100"></el-table-column>
      </el-table>
    </div>
    <div class="back">
      <el-button plain
                 type="info"
                 @click="handleRouterPush({path:'/goods/matter',name:'实物管理工作台'})">返回</el-button>
    </div>
    <add-shift-form ref="addShiftForm"
                    @load="loadData"></add-shift-form>
  </div>
</template>

<script>
import { detailAudit, deleteAudit } from '@/api/things/auditList' //详情
import {
  getShiftSearchList,
  getShiftDetailList,
  deleteShift
} from '@/api/matter/shiftSearch' //详情
import { getAuditList } from '@/api/things/auditList' //审核统计
import autoSearchOrg from '@/components/autocomplete/autoSearchOrg'
import autoSearchName from '@/components/autocomplete/autoSearchName'
import addShiftForm from './addShiftForm'

export default {
  name: 'shiftSearch',
  components: {
    autoSearchOrg,
    autoSearchName,
    addShiftForm
  },
  data() {
    return {
      form: this.clearForm(),
      disabled: false,
      show: false,
      condition: {}, // 查询条件
      shiftSearchData: [],
      shiftDetailData: [], //移位单明细
      auditData: [], // table数组
      pageSearch: getShiftSearchList, // 分页查询api接口
      id: null
    }
  },
  mounted() {
    this.$nextTick(() => {
      this.loadData()
    })
  },
  methods: {
    clearForm() {
      return {
        orgId: '',
        orgId:
          this.$store.state.user.currentUser.org &&
          this.$store.state.user.currentUser.org.id,
        orgName:
          this.$store.state.user.currentUser.org &&
          this.$store.state.user.currentUser.org.name
      }
    },
    loadData() {
      this.$refs.shiftSearch.loadData()
    },
    handleCurrentChange(val) {
      console.log(1,val)
      this.show = true
      getShiftDetailList(val.planNo).then(res => {
        console.log(2,res.data.aaData)
        this.shiftDetailData = res.data.aaData
      })
    },
    // 编辑
    handleDialogFormOpen(bool, item) {
      if (bool) {
        console.log('移位', item)
        this.$refs.addShiftForm.form = JSON.parse(JSON.stringify(item.vo))
        this.$refs.addShiftForm.lsShiftData = item.vo.detailList
        this.$refs.addShiftForm.shiftData = item.vo.detailList
        this.$refs.addShiftForm.isEdit = true
        this.$refs.addShiftForm.dialogForm = true
      }
    },
    //删除
    handleRemove(item) {
      this.$confirm(`是否删除该数据?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          deleteShift(item.planNo).then(res => {
            this.$message({
              type: 'success',
              message: `删除成功!`
            })
            this.loadData()
          })
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消'
          })
        })
    },
    //重置
    resuleBtn(aList) {
      this.$refs[aList].resetFields()
      this.condition = this.clearForm()
    },
    handleRouterPush(val) {
      this.$store.commit('ADD_CACHED_VIEWS', val)
      this.$router.push(val.path)
    }
  }
}
</script>

<style scoped>
</style>
